package com.ruoyi.common.wecom.entity;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

import static com.ruoyi.common.wecom.constants.WeComPropConstants.APP_ID;

/**
 * 发送消息基类
 */
@Data
public class WeComSendBasicMessage {

    private String toUser;
    private String toParty;
    private String toTag;

    public Map<String, Object> getParamMap() {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("agentid", APP_ID);
        this.addMap("touser", toUser, paramMap);
        this.addMap("toparty", toParty, paramMap);
        this.addMap("totag", toTag, paramMap);
        return paramMap;
    }

    private void addMap(String key, String value, Map<String, Object> map) {
        if (StringUtils.isAnyBlank(key, value) || map == null) {
            return;
        }
        map.put(key, value);
    }
}
